package icexam.exam.print;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author ethan
 */
public class ReportViewAction {

    public static void action(String[][] fromtitles, Object[][] objs,int type) throws Exception {
        String reportTitle = fromtitles[0][0];
        String reportTime = fromtitles[0][1];
        String score = fromtitles[0][2];
        ReportProcess rp = null;
        if(type==1)
            rp = new ReportProcess();
        else if(type==0)
            rp = new NewReportProcess();
        else
            rp = new ReportProcessX();
        int index = 0;
        String[] title1 = null;
        String[] title2 = null;
//        String[] minicolumns = null;
        List<Object[]> list = new ArrayList<Object[]>();
        Object[] obj = null;
        List<Object[]> footlist = new ArrayList<Object[]>();
        Object[] footer = null;
        boolean justOnePage = true;
        while ((index + 1) * 9 <= fromtitles[0].length) {
            justOnePage = false;
//            minicolumns = new String[9];
            title1 = new String[9];
            title2 = new String[9];
//            for (int i = 0; i < minicolumns.length; i++) {
////                title1[i] = fromtitles[1][index * 9 + i];
//                title2[i] = fromtitles[2][index * 9 + i];
//                minicolumns[i] = fromtitles[3][index * 9 + i];
//            }
            for (int i = 0; i < objs.length; i++) {
//                if (i < objs.length - 3) {
                    obj = new Object[9];
                    for (int j = 0; j < title1.length; j++) {
                        obj[j] = objs[i][index * 9 + j];
                    }
                    list.add(obj);
//                } else {
//                    footer = new Object[9];
//                    for (int j = 0; j < title1.length; j++) {
//                        footer[j] = objs[i][index * 9 + j];
//                    }
//                    footlist.add(footer);
//                }
            }
            rp.addPreview((index==0?0:1), title1, title1, title2, list, footlist, reportTitle, reportTime,score);
            index++;
            list.clear();
            footlist.clear();
        }
        if (fromtitles[0].length != index * 9) {

//            minicolumns = new String[fromtitles[0].length - index * 9];
            title1 = new String[fromtitles[0].length - index * 9];
            title2 = new String[fromtitles[0].length - index * 9];
            

            for (int i = 0; i < title1.length; i++) {
//                minicolumns[i] = fromtitles[3][index * 9 + i];
                title1[i] = fromtitles[1][index * 9 + i];
                title2[i] = fromtitles[2][index * 9 + i];
            }
            for (int i = 0; i < objs.length; i++) {
//                if (i < objs.length - 3) {
                    obj = new Object[fromtitles[0].length - index * 9];
                    for (int j = 0; j < title1.length; j++) {
                        obj[j] = objs[i][index * 9 + j];
                    }
                    list.add(obj);
//                } else {
//                    footer = new Object[fromtitles[0].length - index * 9];
//                    for (int j = 0; j < title1.length; j++) {
//                        footer[j] = objs[i][index * 9 + j];
//                    }
//                    footlist.add(footer);
//                }
            }
            if (justOnePage == false) {
                rp.addPreview(1, title1, title1, title2, list, footlist, reportTitle, reportTime,score);
            } else {
                rp.addPreview(0, title1, title1, title2, list, footlist, reportTitle, reportTime,score);
            }
        }
        rp.showAll();

    }
}
